package com.etc.controller;

import com.etc.pojo.Area;
import com.etc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("CityController")
public class CityController {
    @Autowired
    CityService cityService;

    @ResponseBody
    @RequestMapping(value = "getCity",method = RequestMethod.GET)
    public List<Area> getCity(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Area> areaList = cityService.getArea();
        request.getSession().setAttribute("areaList",areaList);
        return areaList;
    }

    @ResponseBody
    @RequestMapping(value = "getCityByAreaId",method = RequestMethod.GET)
    public List<Area> getCityByAreaId(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String areaId = (String)request.getSession().getAttribute("areaId");
        System.out.println("----------------------areaId="+areaId);
        List<Area> areaList = cityService.getAreaByAreaId(areaId);
        request.getSession().setAttribute("areaList",areaList);
        return areaList;
    }
}
